package edu.yuhf.utils;

import java.lang.reflect.InvocationTargetException;

import edu.yuhf.dao.iface.UserDao;

public class DaoFactory {
private String db;
	
	public UserDao createUserDao() 
						throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException{
		if(db != null && !db.equals("")){
			//拼接字符串，注意类名包含包名
			String className = "edu.yuhf."+db+".User" + db +"DaoImpl";
			//获取以className字符串为名的类
			Class<UserDao> userDaoImplClass = (Class<UserDao>) Class.forName(className);
			//返回类的实例
			return userDaoImplClass.getDeclaredConstructor().newInstance();
		}
		return null;
	}
	
 
	public String getDb() {
		return db;
	}
 
	public void setDb(String db) {
		this.db = db;
	}

}
